package com.example.zzl.view.fragment.HomeFragment;

import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.zzl.R;
import com.example.zzl.databinding.FragmentSessionBinding;
import com.example.zzl.viewmodel.HomeFragment.SpecialPresenter;


public class SessionFragment extends Fragment implements SpecialPresenter.SpecialCallbackMv{

    private SpecialPresenter presenter;

    public static SessionFragment newInstance(String data) {

        Bundle args = new Bundle();
        args.putString("data", data);
        SessionFragment fragment = new SessionFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        presenter = new SpecialPresenter(getActivity(), this);
        presenter.init();
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        FragmentSessionBinding db = DataBindingUtil.inflate(inflater, R.layout.fragment_session, container, false);
        presenter.setDb(db);
        presenter.initView();
        return db.getRoot();
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        presenter.loadData();
    }

    @Override
    public void startActivity(Class cls, Bundle bundle) {
        startActivity(new Intent(getActivity(), cls).putExtras(bundle));
    }
}
